package com.medibooking.gwt.client.util;

import java.util.Date;

import com.google.gwt.i18n.client.DateTimeFormat;

public abstract class DateFormatter {
    /**
     * Convert to short format
     * 
     * @param date
     * @return
     */
    public static String toShort(Date date) {
        DateTimeFormat dtf = DateTimeFormat.getFormat("E d/M");
        return dtf.format(date).toString();

    }

    /**
     * Convert a number of minutes to hour format Examples: 30 minutes will
     * result in 00:30 60 minutes will result in 01:00 90 minutes will result in
     * 01:30
     * 
     * @param h
     * @return
     */
    public static String minutesToHour(int minutes) {

        int calculatesHours = minutes / 60;
        int calculatedMinutes = minutes - (calculatesHours * 60);

        return (calculatesHours < 10 ? "0" : "") + calculatesHours + ":" + (calculatedMinutes < 10 ? "0" : "") + calculatedMinutes;
    }

    
    public static String formatDate(Date startDate) {
        DateTimeFormat endDateFormatterr = DateTimeFormat.getFormat(" d MMM y");
        return endDateFormatterr.format(startDate);
    }
    @SuppressWarnings({ "deprecation" })
    public static String formatInterval(Date startDate, Date endDate) {
        DateTimeFormat endDateFormatterr = DateTimeFormat.getFormat(" d MMM y");
        String endDateString = endDateFormatterr.format(endDate);
        String startDateFormatPattern = "d ";
        int endMonth = endDate.getMonth();
        int startMonth = startDate.getMonth();
        
        int endYear = endDate.getYear();
        int startYear = startDate.getYear();
        if ( endMonth!=startMonth) {
            startDateFormatPattern+="MMM ";
        }
        if (endYear!=startYear) {
            startDateFormatPattern+="y ";
        }
        DateTimeFormat endDateFormatter = DateTimeFormat.getFormat(startDateFormatPattern.trim());
        String startDateString = endDateFormatter.format(startDate);
        return startDateString+" - "+endDateString;
    }
}
